#!/usr/bin/bash
# 批量转换文档格式为UTF-8
echo  开始批量转换文档格式为UTF-8...

for i in `find . -type f -name \*.h -o -name \*.c -o -name \*.cc -o -name \*.cpp -o -name \*.sh -o -name \*.xml`
do
    filetype=$(file  -bi $i | sed -e 's/.*[ ]charset=//' |tr '[a-z]' '[A-Z')
    if [ $filetype != "US-ASCII" ] && [ $filetype != "UTF-8" ]
    then
        iconv -f GB18030 -t UTF-8 -o iconv.temp $i
        mv  iconv.temp $i
        echo $i filetype is $filetype,change to utf-8!
    fi
    dos2unix $i
done

echo  批量转换文档格式为UTF-8完成...
